import requests
from bs4 import BeautifulSoup
import json
import re

# 发送请求，获取HTML数据
url = "https://ref.gs1.org/ai/"
response = requests.get(url)
html = response.text

# 解析HTML数据
soup = BeautifulSoup(html, 'html.parser')
tableLabels = soup.find('script', id='GS1AI_data')
aits = tableLabels.get_text()
with open("GS1AI_data.json", mode="w", encoding='utf8')as w:
    w.write(aits)
print(aits)

ais = json.loads(aits)['applicationIdentifiers'][1:]
print(ais)
with open("gs1_ai_data.json", mode="w", encoding='utf8')as w:
    w.write(json.dumps(ais, ensure_ascii=False, indent=4))
